package cn.tedu._06interceptor.config;

import cn.tedu._06interceptor.interceptors.MyInterceptor1;
import cn.tedu._06interceptor.interceptors.MyInterceptor2;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //策略1.注册拦截器：默认拦截所有请求
//        registry.addInterceptor(new MyInterceptor1());
        //策略2.注册拦截器：拦截指定请求
//        registry.addInterceptor(new MyInterceptor1())
//                .addPathPatterns("/v1/users/login");
        //策略3.注册拦截器：拦截指定的多个请求
//        registry.addInterceptor(new MyInterceptor1())
//                .addPathPatterns("/v1/users/login", "/v1/users/reg");
        //策略4.注册拦截器：拦截指定的多个请求，比如拦截用户模块的所有请求
//        registry.addInterceptor(new MyInterceptor1())
//                .addPathPatterns("/v1/users/**");
        //策略5.注册拦截器：拦截指定的多个请求，比如拦截用户模块的所有请求，但是排除登录功能
//        registry.addInterceptor(new MyInterceptor1())
//                .addPathPatterns("/v1/users/**")
//                .excludePathPatterns("/v1/users/login");
        registry.addInterceptor(new MyInterceptor1());
        registry.addInterceptor(new MyInterceptor2());
    }
}
